<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改宠物信息')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-pet-edit" th:object="${pet}">
			<input id="id" name="id" type="hidden" th:field="*{id}"/>
			<div class="form-group" >
				<label class="col-sm-3 control-label">宠物名称：</label>
				<div class="col-sm-8">
					<input type="text" name="name" class="form-control" th:field="*{name}" placeholder="请输入宠物名称">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">宠物类型：</label>
				<div class="col-sm-8">
					<input type="text" name="type" class="form-control" th:field="*{type}" placeholder="请输入宠物类型">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">性别：</label>
				<div class="col-sm-8">
					<select id="sex" name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_pet_sex')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sex}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">寄养状态：</label>
				<div class="col-sm-8">
					<select class="form-control m-b" id="fostStatu" name="fostStatu" th:with="type=${@dict.getType('sys_pet_foststatu')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{fostStatu}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" type="text" name="remark" class="form-control" placeholder="请输入备注"></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">宠物照片：</label>
				<input id="filePath" name="filePath" class="form-control" type="file" style="padding: 3px 6px;
                padding-left: 10px;
                border: 1px solid #E7EAEC;
                width: 230px;
                height: 25px;
                line-height: 25px;
                border-left: 3px solid #3FB7EB;
                background: #FAFAFB;
                border-radius: 2px;
                 border: 0px;" >
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: ztree-js" />
	<script type="text/javascript">

		function submitHandler() {
			edit();
		}
		function edit()  {
			var prefix = ctx + "system/pet";
			var name = $("input[name='name']").val();
			var type = $("input[name='type']").val();
			var sex = $('#sex option:selected').val();
			var fostStatu= $('#fostStatu option:selected').val();
			var remark = $('#remark').val();
			var id = $('#id').val();
			var formData = new FormData();
			// if ($('#filePath')[0].files[0] == null) {
			// 	$.modal.alertWarning("请先选择文件路径");
			// 	return false;
			// }
			formData.append("id", id);
			formData.append('name', name);
			formData.append('type', type);
			formData.append('sex', sex);
			formData.append('fostStatu', fostStatu);
			formData.append('remark', remark);
			formData.append('fileName', $("#fileName").val());
			formData.append('file', $('#filePath')[0].files[0]);
			$.ajax({
				processData: false,
				contentType: false,
				cache : false,
				type : "POST",
				url : ctx + "system/pet/edit",
				data :formData,
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
					// $.operate.close();
				}
			});
			// $.operate.save(prefix + "/edit", formData);
		}

	</script>
</body>
</html>
